##配置CMake版本
cmake_minimum_required(VERSION 3.18)

##配置项目名称/语言/版本
project(${version}
    LANGUAGES CXX C
    VERSION 1.0
)

##源代码位置
set(PROJECT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../")
##配置QT路径
set(QT_Version "$ENV{QtVersion}")


if(CMAKE_SIZEOF_VOID_P EQUAL 4)
    set(QT "$ENV{QTDIR}\\..")
    set(QT_PREFIX_PATH "$ENV{QTDIR}")
    list(APPEND CMAKE_PREFIX_PATH ${QT_PREFIX_PATH})
    set(PROJECT_PLATFORM "Win32")
    set(PROJECT_PLATFORM_X "X86")
    add_definitions(-DWIN32)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(QT "$ENV{QTDIR64}\\..")
    set(QT_PREFIX_PATH "$ENV{QTDIR64}")
    list(APPEND CMAKE_PREFIX_PATH ${QT_PREFIX_PATH})
    set(PROJECT_PLATFORM "x64")
    set(PROJECT_PLATFORM_X "X64")
    add_definitions(-DWIN64)
endif()
message(STATUS "--------------------------------------------")
message(STATUS "-QT-:${QT}")
message(STATUS "-QT_PREFIX_PATH-:${QT_PREFIX_PATH}")
message(STATUS "--------------------------------------------")

set(CMAKE_CONFIGURATION_TYPES Debug Release ReleaseDebug)

##全局配置(并行编译、设置内联函数展开、关闭警告、启用comdat折叠,Release版本生成PDB)
if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
    ##Relase版本生成调试信息
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
else()
    add_compile_options(-fpermissive)
endif()

##Release版本内联函数扩展改为默认值
STRING(REPLACE "/Ob1" "" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})

##配置ReleaseDebug版本
set(CMAKE_C_FLAGS_RELEASEDEBUG ${CMAKE_C_FLAGS_RELWITHDEBINFO})
set(CMAKE_CXX_FLAGS_RELEASEDEBUG ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
SET(CMAKE_EXE_LINKER_FLAGS_RELEASEDEBUG ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO})
SET(CMAKE_SHARED_LINKER_FLAGS_RELEASEDEBUG ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO})

STRING(REPLACE "/O2" "/Od" CMAKE_CXX_FLAGS_RELEASEDEBUG ${CMAKE_CXX_FLAGS_RELEASEDEBUG})
STRING(REPLACE "-O2" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
STRING(REPLACE "/Ob1" "" CMAKE_CXX_FLAGS_RELEASEDEBUG ${CMAKE_CXX_FLAGS_RELEASEDEBUG})
##设置Debug版本的文件结尾符
set(CMAKE_DEBUG_POSTFIX d)

##添加 lib路径
link_directories("${PROJECT_SOURCE_DIR}/../build/lib/${PROJECT_PLATFORM}/$(Configuration)")
##控制VS工程生成使用"文件夹"组织结构
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

##将动态库\静态库输出路径定位到特定路径,供调试时使用(否则依赖的库分布在各个文件夹)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}../build/bin/${PROJECT_PLATFORM}/$<CONFIG>")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}../build/lib/${PROJECT_PLATFORM}/$<CONFIG>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}../build/lib/${PROJECT_PLATFORM}/$<CONFIG>")
#message(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})

# 依赖的包，要提前找
find_package(Qt5Core REQUIRED )
find_package(Qt5Widgets REQUIRED )
find_package(Qt5Gui REQUIRED )
find_package(Qt5AxContainer REQUIRED )
find_package(Qt5WebEngineWidgets REQUIRED )
find_package(Qt5Network REQUIRED )

add_subdirectory(modify_PE_core)
add_subdirectory(modify_PE_console)
add_subdirectory(modify_PE_GUI)

# 设置启动项
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT modify_PE_GUI)

